/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.database;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.entities.Category;

/**
 *
 * @author HoangTien
 */
public class SqlCategory {
    MyConnection mc = new MyConnection();
    Category category;
    
    public List<Category> getListCategories() {
        SqlBook sqlBook = new SqlBook();
        List<Category> list = new ArrayList<Category>();
        try {
            ResultSet rs = mc.executeQuery("sp_get_category_all");
            while (rs.next()) {
                category = new Category();
                category.setCateId(rs.getInt("Cate_Id"));
                category.setCateName(rs.getString("Cate_Name")); 
                category.setListBooks(sqlBook.getListBooks(rs.getInt("Cate_Id")));
                list.add(category);
            }
        } catch (SQLException ex) {
            System.out.println("SqlCategory::getListCategories::SQLException \n"+ex);
            ex.printStackTrace();
        }
        return list; 
    }
}
